﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

using CE.User;
using CE.Global;
using CE.Provider;

public partial class provider_ViewProviderUserType : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null || Session[CE.Global.General.ProviderCompanyId] == null)
        {
            Response.Redirect("~/Provider/ProviderSecureLogin.aspx");
        }
        Response.Redirect("~/Provider/ProviderHome.aspx");
        CheckProviderUserType();

        if (!IsPostBack)
        {
            LoadUserTypeList();
        }
    }

    protected void grvProviderUserType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (grvProviderUserType.Rows.Count > 0)
        {
            string strCUID = grvProviderUserType.SelectedDataKey.Values[0].ToString();
            Response.Redirect("ProviderUserType.aspx?CUID=" + strCUID);
        }
    }

    public void LoadUserTypeList()
    {
        DataTable _result = new DataTable();
        UserTypeDB _usertypedb = new UserTypeDB();
        _result = _usertypedb.GetProviderUserTypeList(Convert.ToInt64(Session[CE.Global.General.ProviderCompanyId]));
        if (_result != null && _result.Rows.Count > 0)
        {
            grvProviderUserType.DataSource = _result;
            grvProviderUserType.DataBind();
        }
        else
        {
            grvProviderUserType.DataSource = null;
            grvProviderUserType.DataBind();
        }
    }

    protected void ibtBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("~/Provider/CarInsurance/TableMatching.aspx");
    }

    private void CheckProviderUserType()
    {
        Int64 ProviderUserType = General.CheckProviderUserType(Convert.ToInt64(Session[General.ProviderCompanyId].ToString()),
                                                        Convert.ToInt64(Session[General.UserId].ToString()));
        if (ProviderUserType != 100)
        {
            //Response.Redirect("~/Provider/UserMessage.aspx?errorcode=2000");
            Response.Redirect("~/Provider/UserMessage.aspx?mt=UM&ec=2000");
        }
    }

}
